package org.elanfox.intellicommunity.biz.entity.equipment;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.elanfox.intellicommunity.common.utils.HexUtils;
import org.elanfox.intellicommunity.msg.ienum.BaseStationType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;

/**
 * 基站PO
 *
 * @author loutianxi
 * @date 2019-12-04
 */
@Entity
@Data
@Table(name = "t_base_station")
public class BaseStationPO extends EquipmentPO {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "base_station_id")
    private Integer baseStationId;

    /**
     * 基站IP
     */
    @Column(name = "ip")
    private String ip;
    /**
     * 基站类型
     */
    @Column(name = "station_type")
    private BaseStationType stationType;
    /**
     * 阅读器地址
     */
    @Column(name = "device_addr")
    private long deviceAddr;
    /**
     * 设备地址原始16进制
     */
    @Column(name = "raw_hex_addr")
    private String rawHexAddr;
    /**
     * 设备射频衰减值
     */
    @Column(name = "lf_scope")
    private int lfScope;
    /**
     * 是否启用rssi
     */
    @Column(name = "rssi_enabled")
    private boolean rssiEnabled;
    /**
     * RSSI阈值
     */
    @Column(name = "rssi_limit_val")
    private int rssiLimitVal;
    /**
     * 蜂鸣器状态
     */
    @Column(name = "buzzer_status")
    private boolean buzzerStatus;
    /**
     *
     */
    @Column(name = "filter_interval")
    private int filterInterval;

    /**
     * 基站关联的定位器
     */
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "locator_id")
    @JsonIgnoreProperties("baseStation")
    @NotFound(action = NotFoundAction.IGNORE)
    private LocatorPO locator;

    public String getHexAddr() {
        return this.stationType.getHexCode() + HexUtils.numToHex8(deviceAddr);
    }
}
